package com.houweishi.module.clockingcount.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.houweishi.module.region.domain.BizRegion;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.clockingcount.domain.BizClockingCount;
import com.houweishi.module.clockingcount.service.IBizClockingCountService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 员工打卡统计Controller
 *
 * @author houweishi
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/module/clockingcount")
public class BizClockingCountController extends BaseController {
    @Autowired
    private IBizClockingCountService bizClockingCountService;

    /**
     * 查询员工打卡统计列表
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizClockingCount bizClockingCount) {
        startPage();
        List<BizClockingCount> list = bizClockingCountService.selectBizClockingCountList(bizClockingCount);
        return getDataTable(list);
    }

    /**
     * 导出员工打卡统计列表
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:export')")
    @Log(title = "员工打卡统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizClockingCount bizClockingCount) {
        List<BizClockingCount> list = bizClockingCountService.selectBizClockingCountList(bizClockingCount);
        ExcelUtil<BizClockingCount> util = new ExcelUtil<BizClockingCount>(BizClockingCount.class);
        util.exportExcel(response, list, "员工打卡统计数据");
    }

    /**
     * 获取员工打卡统计详细信息
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizClockingCountService.selectBizClockingCountById(id));
    }

    /**
     * 新增员工打卡统计
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:add')")
    @Log(title = "员工打卡统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizClockingCount bizClockingCount) {
        return toAjax(bizClockingCountService.insertBizClockingCount(bizClockingCount));
    }

    /**
     * 修改员工打卡统计
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:edit')")
    @Log(title = "员工打卡统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizClockingCount bizClockingCount) {
        return toAjax(bizClockingCountService.updateBizClockingCount(bizClockingCount));
    }

    /**
     * 删除员工打卡统计
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:remove')")
    @Log(title = "员工打卡统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizClockingCountService.deleteBizClockingCountByIds(ids));
    }

    /**
     * 查询员工当月打卡统计列表(带上时间查当月记录，不带查员工所有记录，员工id必传)
     */
    //    @PreAuthorize("@ss.hasPermi('module:clockingcount:list2')")
    @GetMapping("/monthList")
    public TableDataInfo list2(BizClockingCount bizClockingCount) {
        startPage();
        List<BizClockingCount> list = bizClockingCountService.selectBizClockingCountListByMonth(bizClockingCount);
        return getDataTable(list);
    }


    /**
     * 查询每个员工本月打卡记录（本部门及下属部门员工信息）
     *
     * @return 打卡集合
     */
    @GetMapping("/treeList")
    public TableDataInfo treeList(BizClockingCount bizClockingCount) {
        List<Map<String, Object>> clockingCountList = bizClockingCountService.selectTreeList2(bizClockingCount);
        return getDataTable(clockingCountList);
    }
}
